#region Copyright
/// <copyright>
/// Copyright (c) 2007 Ilia Shramko.
/// Released under the terms of the GNU General Public License.
/// </copyright>
#endregion

using System;
using System.Collections.Generic;
using System.Text;

namespace Osh.Teletext
{
	public struct CharReplacement
	{
		public static CharReplacement Empty;

		public CharPosition Position;
		public Charset Charset;
		public byte CharCode;
		public byte DiacriticMark;

		public CharReplacement(CharPosition position, Charset charset, byte charCode)
		{
			if(charset == Charset.Empty)
				throw new ArgumentOutOfRangeException("charset");

			Position = position;
			CharCode = charCode;
			Charset = charset;
			DiacriticMark = 0;
		}

		public CharReplacement(CharPosition position, byte charCode, byte diacriticMark)
		{
			Position = position;
			CharCode = charCode;
			Charset = Charset.Empty;
			DiacriticMark = diacriticMark;
		}

		public bool IsCharsetReplacement
		{
			get { return this.Charset != Charset.Empty; }
		}


		public bool IsEmpty
		{
			get { return this.Charset == Charset.Empty && this.CharCode == 0; }
		}

		public override string ToString()
		{
			if(IsCharsetReplacement)
				return "{" + string.Format("Pos={0}, Set={1}, Char=0x{2:X}", this.Position, this.Charset, (int)this.CharCode) + "}";
			else
				return "{" + string.Format("Pos={0}, Char=0x{1:X}, DM=0x{2:X}", this.Position, (int)this.CharCode, (int)this.DiacriticMark) + "}";
		}
	}

}
